package com.gjy.liteflow.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-08-12 10:30:59
 */

public class LifeCyclic implements InitializingBean, DisposableBean, BeanFactoryAware, BeanNameAware {

    private String name;

    public LifeCyclic() {
        System.out.println("1. 调用了构造方法");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
        System.out.println("2. 设置属性值 " + name);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("4. 调用了 BeanFactoryAware.setBeanFactory " + beanFactory);
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("3. 调用了BeanNameAware.setBeanName " + s);
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("9. 调用了DisposableBean.destroy");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("6. 调用了InitializingBean.afterPropertiesSet");
    }

    public void initMethod() {
        System.out.println("7. 自定义init");
    }

    public void destroyMethod() {
        System.out.println("10. 自定义destroy");
    }

    public void work() {
        System.out.println("工作");
    }
}
